#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @File  : ship.py
# @Author: yaqiwe
# @Date  : 2021/10/18
# @Desc  : 飞船的操作

import pygame
from settings import Settings


class Ship:

    def __init__(self, ai_game):
        self.screen = ai_game.screen
        self.screen_rect = ai_game.screen.get_rect()

        self.image = pygame.image.load(Settings.SHIP_IMAGE_ROUTE)
        # 修改图片大小
        self.image = pygame.transform.scale(self.image, Settings.SHIP_SIZE)
        self.rect = self.image.get_rect()
        self.rect.midbottom = self.screen_rect.midbottom

        # 飞船的x坐标
        self.x = self.rect.x

        self.moving_right = False
        self.moving_left = False

    def blitme(self):
        self.screen.blit(self.image, self.rect)

    def update(self):
        """
        更新飞船位置
        :return:
        """

        if self.moving_right and self.rect.right < self.screen_rect.right:
            self.x += Settings.SHIP_SPEED
        if self.moving_left and self.rect.left > 0:
            self.x -= Settings.SHIP_SPEED


        self.rect.x = self.x
